package com.guangjian.asc.user.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

import com.guangjian.asc.question.domain.AnswerSheet;
import com.guangjian.asc.question.domain.Questionnaire;

@RooJavaBean
@RooToString(toStringMethod = "toRooString")
@RooEntity
public class Department {

	@NotNull
	private String name;

	@NotNull
	@ManyToOne(fetch = FetchType.LAZY)
	private Company company;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "department")
	private Set<SystemUser> users = new HashSet<SystemUser>();

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "department")
	private Set<AnswerSheet> answerSheets = new HashSet<AnswerSheet>();

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "department")
	private Set<Questionnaire> questionnaires = new HashSet<Questionnaire>();

	@Override
	public String toString() {
		return company.getName() + " - " + name;
	}
}
